package group2projman;

public class DamageCharge extends BookTransaction {
	int amount;
	
	String description;
	
	public DamageCharge(int id, int bookCopyId, int pAmount, String pDescription) {
		super(id, bookCopyId, Transaction.Type.DAMAGE_CHARGE);
		
		amount = pAmount;
		description = pDescription;
	}
	
	public String listAttributes() {
		StringBuffer result = new StringBuffer(super.listAttributes());
		
		result.append(",str:bookCopyId;").append(0);
		result.append(",dat:dueDate;").append(0);
		result.append(",int:lateFee;").append(0);
		result.append(",int:").append("amount;").append(amount);		
		result.append(",STR").append("description").append(description);
		
		return result.toString();
	}
	
	public boolean loadAttributes(String desc) {
		if (super.loadAttributes(desc))
			return true;
		
		try {
			String[] split = desc.split("[;,]");	
			
			if (!split[12].equals("int:amount"))
				return true;
			amount = Integer.parseInt(split[13]);
			
			if (!split[14].equals("STR:description"))
				return true;
			description = split[15];			
		}  catch (Exception e) {
			// Array index out of bounds or enum value not found
			return true;
		}
		
		return false;
	}		
}
